package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.FileBorrow;
import com.amsp.oa.oademo.mapper.FileBorrowMapper;
import com.amsp.oa.oademo.service.FileBorrowService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class FileBorrowServiceImpl extends ServiceImpl<FileBorrowMapper, FileBorrow> implements FileBorrowService {

    @Override
    public IPage<FileBorrow> getFileBorrowList(Page<FileBorrow> page, String keyword) {
        LambdaQueryWrapper<FileBorrow> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(keyword)) {
            wrapper.like(FileBorrow::getFileNumber, keyword)
                    .or()
                    .like(FileBorrow::getFileName, keyword);
        }
        wrapper.orderByDesc(FileBorrow::getCreateTime);
        return this.page(page, wrapper);
    }
}